package asteroids.expression;

import asteroids.*;
import asteroids.model.programs.Program;

public class GetXPosExpression extends NumericExpression {

	public GetXPosExpression(Expression exp) {
		super(exp);

	}

	public double getValue(Program program) {
		this.updateArguments(program);
		if (this.arg1 instanceof EntityExpression) {

			return ((EntityExpression) arg1).getValue(program).getPosition()
					.getX();
		} else if (this.arg1 instanceof Variable
				&& ((Variable) this.arg1).getRef(program) instanceof EntityExpression) {
			return ((FlyingObject) ((Variable) arg1).getValue(program))
					.getPosition().getX();
		} else {
			return 0.001;
		}
	}
}
